package com.weixin.paleituo.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.weixin.paleituo.R;
import com.weixin.paleituo.adapter.BrokeragePagerAdapter;
import com.weixin.paleituo.base.BaseActivity;
import com.weixin.paleituo.util.UIUtils;
import com.weixin.paleituo.view.ForbidScrollViewpager;

public class BrokerageActivity extends BaseActivity implements View.OnClickListener {

    private TextView mTvShare,mTvMylowber,mTvIntergel;
    private ClassOnFocusListener mOnFocusListener;
    private ForbidScrollViewpager mForbidScrollViewpager;
    private BrokeragePagerAdapter mBrokeragePagerAdapter;
    private ImageView mIvBack;


    public static void startActivity(Context context){
        Intent intent=new Intent(context,BrokerageActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        setContentView(R.layout.activity_brokerage);
        mTvShare = findViewById(R.id.tv_shar_activity_brokerage);
        mTvMylowber = findViewById(R.id.tv_mylowber_activity_brokerage);
        mTvIntergel = findViewById(R.id.tv_intergel_activity_brokerage);
        mForbidScrollViewpager = findViewById(R.id.viewpager_activity_brokerage);
        mIvBack = findViewById(R.id.iv_back_activity_brokerage);
    }

    @Override
    protected void initData() {
        super.initData();
        mOnFocusListener = new ClassOnFocusListener();
        mBrokeragePagerAdapter = new BrokeragePagerAdapter(getSupportFragmentManager());
        mForbidScrollViewpager.setAdapter(mBrokeragePagerAdapter);
        mForbidScrollViewpager.setCurrentItem(0,false);

    }

    @Override
    protected void initEvent() {
        super.initEvent();
        mTvShare.setOnFocusChangeListener(mOnFocusListener);
        mTvMylowber.setOnFocusChangeListener(mOnFocusListener);
        mTvIntergel.setOnFocusChangeListener(mOnFocusListener);
        mIvBack.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_back_activity_brokerage:
                finish();
                break;


        }

    }

    /**
     * 监听点击对象
     */
  class ClassOnFocusListener   implements View.OnFocusChangeListener {

      @Override
      public void onFocusChange(View v, boolean hasFocus) {
          switch (v.getId()){
              case R.id.tv_shar_activity_brokerage:
                  if (hasFocus) {
                      mTvShare.setTextColor(UIUtils.getColor(R.color.c_ff383838));
                      mForbidScrollViewpager.setCurrentItem(0,false);
                  } else {
                      mTvShare.setTextColor(UIUtils.getColor(R.color.c_ff999999));

                  }

                  break;
                  case R.id.tv_mylowber_activity_brokerage:

                      if (hasFocus) {
                          mTvMylowber.setTextColor(UIUtils.getColor(R.color.c_ff383838));
                          mForbidScrollViewpager.setCurrentItem(1,false);
                      } else {
                          mTvMylowber.setTextColor(UIUtils.getColor(R.color.c_ff999999));

                      }
                  break;
              case R.id.tv_intergel_activity_brokerage:
                  if (hasFocus) {
                      mTvIntergel.setTextColor(UIUtils.getColor(R.color.c_ff383838));
                      mForbidScrollViewpager.setCurrentItem(2,false);
                  } else {
                      mTvIntergel.setTextColor(UIUtils.getColor(R.color.c_ff999999));
                  }
                  break;

          }




      }
  }

}
